// components/tip/tip.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    msg: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {
        if (newVal && this.properties.type !== 'error') {
          let me = this;
          setTimeout(() => {
            me.closeMsg()
          }, 3000)
        }
      }
    },
    type: {
      type: String,
      value: 'normal',  //error //success
      observer: function (newVal, oldVal, changedPath) {

      }
    },

  },

  /**
   * 组件的初始数据
   */
  data: {
    animationData: ''
  },
  ready: function () {
    this.animation('start');
  },

  /**
   * 组件的方法列表
   */
  methods: {
    animation: function (p) {
      let animation = wx.createAnimation({
        duration: 300,
        timingFunction: "ease",
        delay: 0,
        transformOrigin: "50% 50%",
      });
      if (p === 'start') {
        animation.translate(0).step();
      } else if (p === 'end') {
        animation.translate(0, '100%').step();
      }
      this.setData({
        animationData: animation.export(),
      });
    },
    closeMsg: function () {
      this.animation('end');
      setTimeout(() => {
        this.triggerEvent('closemsg', {}, {});
      }, 300);
      
    }
  }
})
